import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

import { Camera, CameraOptions } from '@ionic-native/camera';

/**
 * Generated class for the NativePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-native',
  templateUrl: 'native.html',
})
export class NativePage {

  images: Array<{ src: String }>;

  constructor(public navCtrl: NavController, public navParams: NavParams,
    private camera: Camera
  ) {

    this.images = [];
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad NativePage');
  }



  takePhoto() {
    console.log(1);
    // 设置选项
    const options: CameraOptions = {
      quality: 50,
      destinationType: this.camera.DestinationType.DATA_URL,
      sourceType: this.camera.PictureSourceType.CAMERA,
      encodingType: this.camera.EncodingType.JPEG,
      allowEdit: false,
      mediaType: this.camera.MediaType.PICTURE
    }

    // 获取图片
    this.camera.getPicture(options).then((imageData) => {
      // 获取成功
      let base64Image = 'data:image/jpeg;base64,' + imageData;
      this.images.unshift({
        src: base64Image
      })
    }, (err) => {
      console.log('获取图片失败');
    });
  }
  clearPhote() {
    this.images = [];
  }
  saoyisao() {
    console.log(`saoyisao`);
    this.navCtrl.push("ScanPage")
  }



}
